import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QVBoxLayout, QWidget
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtCore import QUrl


class VideoEditor(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("简单视频编辑器")
        self.setGeometry(100, 100, 800, 600)

        # 创建 QMediaPlayer
        self.player = QMediaPlayer(self)

        # 创建按钮并连接信号
        self.initUI()

    def initUI(self):
        layout = QVBoxLayout()

        self.play_button = QPushButton("播放视频", self)
        self.play_button.clicked.connect(self.play_video)

        self.load_button = QPushButton("加载视频", self)
        self.load_button.clicked.connect(self.load_video)

        layout.addWidget(self.load_button)
        layout.addWidget(self.play_button)

        container = QWidget()
        container.setLayout(layout)
        self.setCentralWidget(container)

    def load_video(self):
        file_name, _ = QFileDialog.getOpenFileName(self, "选择视频文件")
        if file_name:
            self.player.setMedia(QMediaContent(QUrl.fromLocalFile(file_name)))

    def play_video(self):
        self.player.play()


# 运行应用程序
if __name__ == "__main__":
    app = QApplication(sys.argv)
    editor = VideoEditor()
    editor.show()
    sys.exit(app.exec_())